<?php

declare(strict_types=1);

namespace Tool\Database\MockType;

use Tool\Database\AbstractColumn;

/**
 * 整数类型.
 */
class Decimal extends AbstractColumn
{
    public function __construct(array &$column)
    {
        parent::__construct($column);

        $this->extArgs[] = 0.01;
        $this->extArgs[] = floatval(100);
    }

    /**
     * {@inheritDoc}
     */
    protected function mock()
    {
        if (2 === count($this->extArgs)) {
            return $this->randFloat(floatval($this->extArgs[0]), floatval($this->extArgs[1]));
        }

        return $this->defaultValue(0.0);
    }

    protected function randFloat(float $min = 0, float $max = 1)
    {
        $rand = $min + mt_rand() / mt_getrandmax() * ($max - $min);

        return floatval(number_format($rand, $this->getScale(), '.', null));
    }
}
